package demoMod.invincibleOne.cards.invincible;

import basemod.ReflectionHacks;
import basemod.helpers.CardModifierManager;
import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.common.ApplyPowerAction;
import com.megacrit.cardcrawl.actions.common.SpawnMonsterAction;
import com.megacrit.cardcrawl.actions.unique.SummonGremlinAction;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.core.Settings;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.localization.CardStrings;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import com.megacrit.cardcrawl.monsters.exordium.Cultist;
import com.megacrit.cardcrawl.powers.RitualPower;
import demoMod.invincibleOne.InvincibleOneMod;
import demoMod.invincibleOne.enums.CardTagsEnum;
import demoMod.invincibleOne.modifiers.ExhaustAtStartOfCombatMod;
import demoMod.invincibleOne.powers.ConscriptionPower;
import demoMod.invincibleOne.relics.TaskGoal;

public class Conscription extends AbstractInvincibleCard {
    public static final String ID = InvincibleOneMod.makeID("Conscription");

    private static final CardStrings cardStrings = CardCrawlGame.languagePack.getCardStrings(ID);
    public static final String NAME = cardStrings.NAME;
    public static final String DESCRIPTION = cardStrings.DESCRIPTION;
    public static final String IMG_PATH = "cards/Conscription.png";

    private static final CardType TYPE = CardType.SKILL;
    private static final CardRarity RARITY = CardRarity.RARE;
    private static final CardTarget TARGET = CardTarget.NONE;

    private static final int COST = -2;

    public Conscription() {
        super(ID, NAME, InvincibleOneMod.getResourcePath(IMG_PATH), COST, DESCRIPTION, TYPE, RARITY, TARGET);
        this.modifier = new ExhaustAtStartOfCombatMod();
        CardModifierManager.addModifier(this, modifier);
        this.baseMagicNumber = this.magicNumber = 1;
        this.tags.add(CardTagsEnum.ALERT);
    }

    @Override
    public boolean onBattleStart() {
        TaskGoal.AddToAlertQueue(2, new TaskGoal.AlertLambda() {
            @Override
            public void run() {
                addToBot(new SummonGremlinAction(ConscriptionPower.gremlins));
                addToBot(new AbstractGameAction() {
                    @Override
                    public void update() {
                        for (AbstractMonster monster : ConscriptionPower.gremlins) {
                            if (monster != null && !monster.isDeadOrEscaped() && !(ReflectionHacks.getPrivate(monster, AbstractMonster.class, "move") == null)) {
                                monster.createIntent();
                            }
                        }
                        isDone = true;
                    }
                });
            }
        });

        if (upgraded) {
            AbstractPlayer p = AbstractDungeon.player;
            addToBot(new ApplyPowerAction(p, p, new ConscriptionPower(p, 2)));
        }
        return true;
    }

    @Override
    public Runnable getUpgradeAction() {
        return () -> upgradeMagicNumber(1);
    }

    @Override
    public void use(AbstractPlayer p, AbstractMonster m) {

    }
}
